package utils;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;

import java.util.concurrent.TimeUnit;

public class WebDriverFactory {

    public static final String CHROME = "chrome";
    public static final String FIREFOX = "firefox";

    public static WebDriver initDriver(String browser)
    {
        WebDriver testDriver = null;
        if (browser.equalsIgnoreCase(FIREFOX)){
            testDriver = new FirefoxDriver();
        } else if (browser.equalsIgnoreCase(CHROME)) {
            System.setProperty("webdriver.chrome.driver", "soft\\chromedriver.exe");
            testDriver = new ChromeDriver();
        } else {
            Assert.fail(ReportWriter.errorDriverUnknown(browser));
        }

        testDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        testDriver.manage().window().maximize();
        ReportWriter.info(browser.toUpperCase() +" has been successfully initialized!");
        return testDriver;
    }
}